package com.xinqi.modules.course.clazz.convert;

import com.xinqi.common.base.utils.json.JSON;
import com.xinqi.common.mapstruct.CommonConvertConfig;
import com.xinqi.modules.course.clazz.domain.ClassStudentEntity;
import com.xinqi.modules.course.clazz.dto.req.ClassStudentCreateDTO;
import com.xinqi.modules.course.clazz.dto.req.ClassStudentUpdateDTO;
import com.xinqi.modules.course.clazz.dto.req.MasterClassStudentUpdateDTO;
import com.xinqi.modules.course.clazz.dto.rsp.ClassStudentResultDTO;
import com.xinqi.modules.user.user.dto.req.UserImitateUpdateDTO;
import com.xinqi.modules.user.user.dto.rsp.UserResultDTO;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;

import java.util.List;
import java.util.Objects;

/**
 * 班级学生表转换
 *
 * @author: system
 * @date: 2023/01/17
 */
@Mapper(config = CommonConvertConfig.class)
public abstract class ClassStudentConvert {
    @Mapping(target = "auditContent", ignore = true)
    public abstract ClassStudentEntity create(ClassStudentCreateDTO s);

    public abstract ClassStudentEntity create(Long classId);

    public abstract ClassStudentEntity update(ClassStudentUpdateDTO s, @MappingTarget ClassStudentEntity t);

    public abstract ClassStudentEntity update(ClassStudentUpdateDTO s);

    public abstract ClassStudentResultDTO convert(ClassStudentEntity s);

    public abstract List<ClassStudentResultDTO> convertList(List<ClassStudentEntity> list);

    public abstract ClassStudentUpdateDTO convert(ClassStudentResultDTO s);

    public abstract ClassStudentEntity convertEntity(ClassStudentResultDTO s);

    public abstract ClassStudentEntity convert(Long courseId, Long classId, Long studentId);

    public abstract ClassStudentResultDTO convert(UserResultDTO user);

    public abstract UserImitateUpdateDTO convert(MasterClassStudentUpdateDTO s);

    @AfterMapping
    public void after(ClassStudentCreateDTO s, @MappingTarget ClassStudentEntity t) {
        if (!Objects.isNull(s.getAuditContent())) {
            t.setAuditContent(JSON.stringify(s.getAuditContent().getDataList()));
        }
    }

}
